package com.lsb.config;

import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommandLineRunnerConfig {
    @Bean
    public CommandLineRunner commandLineRunner(ApplicationContext context){
        //lambda表达式,相当于代替匿名内部类
        // 返回一个  函数式接口的实现类对象
        return (java.lang.String... args)->{
            System.out.println("由SpringBoot自动注册的Bean实例有: ");
            String[] beanNames = context.getBeanDefinitionNames();
            for (String beanName : beanNames) {
                System.out.println(beanName);
            }
        };
    }
}
